<template>
	<div>
		<Header />
		<uni-scroll-view class="presets" :lower-threshold="50">
			<view v-for="preset in defaultTypes" @click="routerPush(preset)" class="preset-tag">{{preset}}</view>
		</uni-scroll-view>
		<uni-collapse ref="collapse" v-if="types.length">
			<uni-collapse-item title="全部分类" :open="false">
				<div class="collapse-wrap">
					<view v-for="preset in types" @click="routerPush(preset)" class="preset-tag">{{preset}}</view>
				</div>
			</uni-collapse-item>
		</uni-collapse>
	</div>
</template>

<script lang="ts">
	import { http } from "../../utils/api.service"
	import Header from '../components/header.vue'

		export default {
		components: {
			Header
		},
		data() {
			return {
				types: [],
				defaultTypes: []
			}
		},
		onLoad(options : { id : string }) {
			const id = options.id
			this.getTypes(id)
		},
		methods: {
			routerPush(text : string) {
				uni.navigateTo({
					url: "/pages/detail/index" + `?keyword=${text}`
				})
			},
			getTypes(id : string) {
				http({
					url: "/category/types",
					method: "GET",
					data: {
						id
					}
				}).then((res : any) => {
					console.log(res);
					this.defaultTypes = res.types.slice(0, 50)
					this.types = res.types
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.presets,
	.collapse-wrap {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-evenly;
		font-size: 13px;

		.preset-tag {
			display: flex;
			align-items: center;
			justify-content: center;
			width: auto;
			border-radius: 10px;
			margin: 5px;
			padding: 6px;
			background-color: #F4EFE9;
		}
	}

	.presets {
		padding-top: 10px;
	}
</style>